# 定义
dict1={}
dict2=dict( [('name','yuhang'),('age',18)] )
print(dict2) #{'name': 'yuhang', 'age': 18}

# 遍历
dict3=dict( [('name','yuhang'),('age',18)] )
for i in dict3:
    print(i) #name age 得到的是key


for item in dict3.items():
    print(item) #('name', 'yuhang') ('age', 18)

for key,val in dict3.items():
    print(key,val) #name yuhang   age 18



dict4=dict( [('name','yuhang'),('age',18),('score',18)] )
for val in dict4.values():
    print(val) #yuhang 18 18  包含所有value的列表 不去重

for key in dict4.keys():
    print(key) #name age score


if('name' in dict4):
    print("name在dict4中" )

# print(dict4['sex']) #找不到会报错
print(dict4.get('sex')) #找不到返回none

# 删除
dict4.pop('name')
print(dict4)

dict4.clear()
print(dict4)